package view
{
	import com.common.Color;
	import com.util.MakeChildrenUtil;
	
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import xm.align.AlignFactory;
	import xm.align.box.AlignHBox;
	import xm.align.box.AlignVBox;
	import xm.components.button.SWCButton;
	import xm.components.text.TruncateTextField;
	import xm.core.XMSprite;
	import xm.definition.Align;
	import xm.view.ViewDefault;
	
	
	/**
	 * <br> 클래스 설명 : </br>
	 * @author 강석민
	 */	
	public class View04_AlignFactory extends ViewDefault
	{
		//-----------------------------------------------------------------------------------
		// public vars
		//-----------------------------------------------------------------------------------
		//-----------------------------------------------------------------------------------
		// protected / internal vars
		//-----------------------------------------------------------------------------------
		//-----------------------------------------------------------------------------------
		// private vars
		//-----------------------------------------------------------------------------------
		//-----------------------------------------------------------------------------------
		// public functions
		//-----------------------------------------------------------------------------------
		
		/**
		 * constructor 
		 */	
		public function View04_AlignFactory()
		{
			super();
		}
		
		/**
		 * commitProperties
		 */		
		override public function commitProperties():void
		{
			super.commitProperties();
		}
		
		/**
		 * updateDisplayList
		 */		
		override public function updateDisplayList( enforce : Boolean = false ):void
		{
			super.updateDisplayList(enforce);
		}
		
		//-----------------------------------------------------------------------------------
		// life cycle functions
		//-----------------------------------------------------------------------------------
		
		/**
		 * createChildren
		 */		
		override public function createChildren():void
		{
			super.createChildren();
			
			//============================================================
			//						액션바
			//============================================================
			//네비게이션컨텐츠
			var navigationBtn : SWCButton = MakeChildrenUtil.makeSwcBtn( new BTN_PREV );
			this.navigationContent = MakeChildrenUtil.makeNavigationContent( navigationBtn );
			//타이틀 컨텐츠
			var titleTextField : TextField = MakeChildrenUtil.makeTextField( "View04_AlignFactory", Color.WHITE, 20);
			this.titleContent  = MakeChildrenUtil.makeTitleContent( titleTextField );
			//액션컨텐츠
			var actionBtn : SWCButton = MakeChildrenUtil.makeSwcBtn( new BTN_NEXT ); 
			this.actionContent = MakeChildrenUtil.makeActionContent( actionBtn );
			actionBtn.addEventListener(MouseEvent.CLICK , onActionBtnClick );
			//============================================================
			//						화면구성
			//============================================================
			
			var xmList : Array = [];
			var xms : XMSprite;
			var i:int, len:int;
			i=0;
			len=5;
			
			while( i<len )
			{
				xms = MakeChildrenUtil.makeXMSprite( null, 30, 30, 0x000000 );
				xmList.push( xms );
				addChild( xms );
				++i;
			}
			
			
			
			/*
			var af : AlignFactory = new AlignFactory().setDefaultCellSize(40).addSimpleList( xmList ).setPosition( 100, 100 );
			af.workingAlign();
			*/
			
			/*
			var af : AlignFactory = new AlignFactory();
			
			af.addSimpleItem( xmList[ 0 ], [10,0,0,0] );
			af.addSimpleItem( xmList[ 1 ], [10,0,0,10] );
			af.addSimpleItem( xmList[ 2 ], [10,0,0,0] );
			af.addSimpleItem( xmList[ 3 ], [30,0,0,30] );
			af.addSimpleItem( xmList[ 4 ], [10,0,0,0] );
			af.workingAlign();
			*/
			
			
			var af : AlignFactory = new AlignFactory();
			af.addSimpleItem( xmList[ 0 ], [10,0,0,0] );
			af.addSimpleBox(
				
				new AlignHBox( 3, [150, 150, availableWidth-300], [Align.RIGHT, Align.RIGHT, Align.RIGHT] )
					.addSimpleItem( xmList[ 1 ], [10,0,0,10] )
					.addSimpleItem( xmList[ 2 ], [10,10,0,0] )
					.addSimpleBox( new AlignVBox( 1, [100], [Align.CENTER] ).addSimpleItem( xmList[ 3 ], [0,0,0,0] ) )
//					.addItem( new AlignObject( xmList[ 3 ], null, new AlignInfo( [] ) )
			);
			af.addSimpleItem( xmList[ 4 ], [10,0,0,0] );
			af.workingAlign();
			
			
		}
		
		/**
		 * createComplete
		 */		
		override public function creationComplete():void
		{
			super.creationComplete();
		}
		
		/**
		 * add
		 */		
		override public function add():void
		{
			super.add();
		}
		
		/**
		 * startAddTransition : add 완료 후 transition 이 있으면 화면전환효과를 실행한다.
		 */		
		override public function startAddTransition():void
		{
			super.startAddTransition();
		}
		
		/**
		 * startAddTransition 완료.
		 */		
		override public function endAddTransition():void
		{
			super.endAddTransition();
		}
		
		/**
		 * startRemoveTransition : remove 하기 전 transition 이 있으면 화면전환효과를 실행한다.
		 */		
		override public function startRemoveTransition():void
		{
			super.startRemoveTransition();
		}
		
		/**
		 * startRemoveTransition 완료.
		 */		
		override public function endRemoveTransition():void
		{
			super.endRemoveTransition();
		}
		
		/**
		 * remove
		 */		
		override public function remove():void
		{
			super.remove();
		}
		
		/**
		 * destroy
		 */		
		override public function destroy():void
		{
			super.destroy();
		}
		
		//-----------------------------------------------------------------------------------
		// setter / getter
		//-----------------------------------------------------------------------------------
		//-----------------------------------------------------------------------------------
		// protected functions
		//-----------------------------------------------------------------------------------
		//-----------------------------------------------------------------------------------
		// internal functions
		//-----------------------------------------------------------------------------------
		//-----------------------------------------------------------------------------------
		// private functions
		//-----------------------------------------------------------------------------------
		//-----------------------------------------------------------------------------------
		// event handler
		//-----------------------------------------------------------------------------------
		/**
		 *
		 */
		private function onActionBtnClick(e:MouseEvent):void
		{
			this.navigator.add( View05_SWCButton );	
		}
		
		
	}
}